<template>
  <div class="container-content">
    <el-form
      ref="formRef"
      :model="formObject"
      label-width="100px"
      label-position="left"
      :rules="rules"
    >
      <el-collapse v-model="activeNames">
        <el-collapse-item title="基础信息" name="1">
            <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item
              label="合同类型"
              prop="contractProcureEntity.procureType"
            >
              <el-select
                :readonly="id ? true : false"
                v-model="formObject.contractProcureEntity.procureType"
                placeholder="请选择"
                style="width: 100%"
                :disabled="change"
              >
                <!-- @change="getContractTypeOptions" -->
                <el-option
                  v-for="item in typeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同模版">
              <el-select
                :readonly="id ? true : false"
                v-model="contractType"
                placeholder="请选择"
                style="width: 100%"
                :disabled="change"
                @change="getContractContent"
              >
                <el-option
                  v-for="item in contractTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
            <el-col :span="12">
              <el-form-item
                label="合同名称"
                prop="contractProcureEntity.contractName"
              >
                <el-input
                  v-model="formObject.contractProcureEntity.contractName"
                ></el-input>
              </el-form-item>
            </el-col>
             <el-col :span="12">
              <el-form-item label="合同金额">
                <el-input
                  v-model="formObject.contractProcureEntity.money"
                  :disabled="change"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同金额大写" label-width="110px">
                <el-input
                  v-model="formObject.contractProcureEntity.moneyUpper"
                  :disabled="change"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购部门" label-width="110px">
                <el-input
                  v-model="formObject.contractProcureEntity.deptName"
                >
                
                <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('deptId')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
       
        </el-collapse-item>
        <el-collapse-item title="供应商信息" name="2">
               <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item
                label="项目"
                prop="contractProcureEntity.projectName"
              >
                <el-input
                  v-model="formObject.contractProcureEntity.projectName"
                  :disabled="change"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('project')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="供应商"
                prop="contractProcureEntity.supplierName"
              >
                <el-input
                  v-model="formObject.contractProcureEntity.supplierName"
                  :disabled="change"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('supplier')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供货方">
                <el-input
                  v-model="formObject.contractProcureEntity.supplierGoodsName"
                  :disabled="change"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('supplierGoods')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供货方联系人">
                <el-input
                  v-model="formObject.contractProcureEntity.supplierContactName"
                  :disabled="change"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('supplierContact')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系人职务">
                <el-input
                  v-model="formObject.contractProcureEntity.contactPosition"
                  :disabled="change"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系人手机号">
                <el-input
                  v-model="formObject.contractProcureEntity.telPhone"
                  :disabled="change"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供货方地址">
                <el-input
                  v-model="formObject.contractProcureEntity.supplierAddress"
                  :disabled="change"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结算方">
                <el-input
                  v-model="formObject.contractProcureEntity.settlementName"
                  :disabled="change"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('settlement')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="收款方">
                <el-input
                  v-model="formObject.contractProcureEntity.payableName"
                  :disabled="change"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('payable')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="邮箱">
                <el-input
                  v-model="formObject.contractProcureEntity.email"
                  clearable
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="change ? '变更原因' : '备注'">
                <el-input
                  v-model="formObject.contractProcureEntity.remarks"
                  type="textarea"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="财务信息" name="3">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item
                label="付款方式"
                prop="contractProcureEntity.payTypeName"
              >
                <el-input
                  v-model="formObject.contractProcureEntity.payTypeName"
                  
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('pay')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="保证金金额" label-width="110px">
                <el-input
                  v-model="formObject.contractProcureEntity.marginMoney"
                  :disabled="change"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结算币别">
                <el-input
                  v-model="
                    formObject.contractProcureEntity.settlementCurrencyName
                  "
                  :disabled="change"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('currency')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="汇率">
                <el-input
                  v-model="formObject.contractProcureEntity.rate"
                  clearable
                  :disabled="change"
                  @change="changeRate"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="定价时点">
                <el-select
                  v-model="formObject.contractProcureEntity.priceTimePoint"
                  placeholder="请选择"
                  style="width: 100%"
                  :disabled="change"
                >
                  <el-option :key="1" label="系统日期" :value="1"> </el-option>
                  <el-option :key="2" label="单据日期" :value="2"> </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="本位币">
                <el-input
                  v-model="
                    formObject.contractProcureEntity.standardCurrencyName
                  "
                  :disabled="change"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('standardCurrency')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="付款条件">
                <el-input
                  v-model="formObject.contractProcureEntity.paymentTermsName"
                  :disabled="change"
                >
                  <i
                  v-if="!change"
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('paymentTerms')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="合同总金额本位币" label-width="150px">
                <el-input
                  v-model="formObject.contractProcureEntity.totalAmountCurrency"
                  clearable
                  :disabled="change"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="汇率类型">
                <el-input
                  v-model="formObject.contractProcureEntity.rateType"
                  clearable
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="showDialog('rateType')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="签订日期">
                <el-date-picker
                  v-model="formObject.contractProcureEntity.signTime"
                  type="date"
                  placeholder="选择日期"
                  style="width: 100%"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  :disabled="change"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开始日期">
                <el-date-picker
                  v-model="formObject.contractProcureEntity.startTime"
                  type="date"
                  placeholder="选择日期"
                  style="width: 100%"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  :disabled="change"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结束日期">
                <el-date-picker
                  v-model="formObject.contractProcureEntity.endTime"
                  type="date"
                  placeholder="选择日期"
                  style="width: 100%"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  :disabled="change"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="是否含税">
                <el-radio
                  border
                  :label="1"
                  v-model="formObject.contractProcureEntity.isIncludeTax"
                  >是</el-radio
                >
                <el-radio
                  border
                  :label="2"
                  v-model="formObject.contractProcureEntity.isIncludeTax"
                  >否</el-radio
                >
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否价外税">
                <el-radio
                  border
                  :label="1"
                  v-model="formObject.contractProcureEntity.isExtraPriceTax"
                  >是</el-radio
                >
                <el-radio
                  border
                  :label="2"
                  v-model="formObject.contractProcureEntity.isExtraPriceTax"
                  >否</el-radio
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="合同模板" name="4">
               <Editor
          ref="editor"
          editor-id="editor"
          height="500px"
          :template-content="formObject.contractProcureEntity.contractContent"
        />
        </el-collapse-item>
        <el-collapse-item title="合同明细" name="5">
<template v-if="formObject.contractProcureEntity.procureType !== 2">
          <div class="desc-title">物料列表</div>
          <el-button type="text" size="medium" @click="addNewRow('material')">
            新增行
          </el-button>
          <div class="floatright mb10">
            <el-button type="primary" plain @click="showDialog('order')"
              >选单</el-button
            >

            <el-button type="primary" plain @click="showDialog('material', -1)"
              >导入物料</el-button
            >
          </div>
          <el-table
            :data="formObject.materialDetailEntities"
            style="width: 100%"
            highlight-current-row
            border
            :summary-method="getSummaries"
            show-summary
          >
            <el-table-column label="操作" fixed>
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="handleDataDelete(scope.$index, scope.row, 'material')"
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column
              type="index"
              label="序号"
              width="50"
              align="center"
            ></el-table-column>
            <el-table-column prop="materialCode" width="150">
              <template slot="header">
                物料编码<span class="required">*</span>
              </template>
              <template slot-scope="scope">
                <el-form-item
                  label-width="0px"
                  style="margin: 0"
                  :rules="rules.materialCode"
                  :prop="
                    'materialDetailEntities.' + scope.$index + '.materialCode'
                  "
                >
                  <el-input
                    v-model="scope.row.materialCode"
                    clearable
                    :readonly="change ? true : false"
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                      @click="showDialog('material', scope.$index)"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="物料名称" prop="materialName" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="materialName"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.materialName" clearable disabled>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="规格型号" prop="model" width="150">
              <template slot-scope="scope">
                <el-form-item prop="model" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.model" clearable  disabled>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column prop="purchaseUnitName" width="150">
              <template slot="header">
                采购单位<span class="required">*</span>
              </template>
              <template slot-scope="scope">
                <el-form-item
                  label-width="0px"
                  style="margin: 0"
                  :rules="rules.purchaseUnitName"
                  :prop="
                    'materialDetailEntities.' +
                    scope.$index +
                    '.purchaseUnitName'
                  "
                >
                  <el-input
                    v-model="scope.row.purchaseUnitName"
                     :disabled="change"
                    clearable
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                      @click="showDialog('purchaseUnit', scope.$index)"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column prop="pricingUnitName" width="150">
              <template slot="header">
                计价单位<span class="required">*</span>
              </template>
              <template slot-scope="scope">
                <el-form-item
                  label-width="0px"
                  style="margin: 0"
                  :rules="rules.pricingUnitName"
                  :prop="
                    'materialDetailEntities.' +
                    scope.$index +
                    '.pricingUnitName'
                  "
                >
                  <el-input
                    v-model="scope.row.pricingUnitName"
                     :disabled="change"
                    clearable
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                      @click="showDialog('pricingUnit', scope.$index)"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="计价数量" prop="pricingNum" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="pricingNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.pricingNum" clearable  :disabled="change">
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="变更类型" prop="changeType" width="150" v-if="change">
              <template slot-scope="scope">
                <el-form-item
                  prop="pricingNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.changeType" clearable>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="原合同数量" prop="originalNumber" width="150" v-if="change">
              <template slot-scope="scope">
                <el-form-item
                  prop="pricingNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.originalNumber" clearable readonly>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="原含税单价" v-if="change" prop="originalContainsTaxPrice" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="pricingNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.originalContainsTaxPrice" clearable  :disabled="change">
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="单价" prop="price" width="150">
              <template slot-scope="scope">
                <el-form-item prop="price" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.price"  disabled clearable>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="交货日期" width="250" prop="deliveryDate">
              <template slot-scope="scope">
                <el-form-item
                  prop="deliveryDate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-date-picker
                    v-model="scope.row.deliveryDate"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                  >
                  </el-date-picker>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="含税单价" prop="taxPrice" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="taxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxPrice" clearable>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column
                        label="折扣率%"
                        prop="discountRate"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="discountRate"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.discountRate"
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

            <el-table-column label="金额" prop="amountMoney" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="amountMoney"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.amountMoney"  disabled clearable>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="合同数量" prop="number" width="150">
              <template slot-scope="scope">
                <el-form-item prop="number" label-width="0px" style="margin: 0">
                  <el-input
                    v-model="scope.row.number"
                    clearable
                    @change="caculateNum(scope.row, scope.$index)"
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="税率%" prop="taxRate" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="taxRate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.taxRate"
                    
                    clearable
                    @change="caculateNum(scope.row, scope.$index)"
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                      @click="showDialog('taxRate', scope.$index)"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column label="直接汇率">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="directRate"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.directRate"
                                    :readonly="change ? true : false"
                                    clearable
                                    @change="
                                        caculateNum(scope.row, scope.$index)
                                    "
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="
                                            showDialog('rate', scope.$index)
                                        "
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column label="间接汇率">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="indirectRate"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.indirectRate"
                                    readonly
                                    clearable
                                    @change="
                                        caculateNum(scope.row, scope.$index)
                                    "
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column> -->
            <el-table-column label="税额" prop="taxAmount" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="taxAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxAmount"  disabled clearable>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="价税合计" prop="totalTaxPrice" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="totalTaxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.totalTaxPrice"
                    disabled
                    clearable
                    @change="caculateNum(scope.row, scope.$index)"
                  >
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column
              label="需求组织"
              prop="requireDeptName"
              width="150"
            >
              <template slot-scope="scope">
                <el-form-item
                  prop="requireDeptName"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.requireDeptName"
                    clearable
                    disabled
                  >
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column
              label="收料组织"
              prop="receivingDeptName"
              width="150"
            >
              <template slot-scope="scope">
                <el-form-item
                  prop="receivingDeptName"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.receivingDeptName"
                    clearable
                    disabled
                  >
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column prop="settlementDeptName" width="150">
              <template slot="header">
                结算组织<span class="required">*</span>
              </template>
              <template slot-scope="scope">
                <el-form-item
                  label-width="0px"
                  style="margin: 0"
                  :rules="rules.settlementDeptName"
                  :prop="
                    'materialDetailEntities.' +
                    scope.$index +
                    '.settlementDeptName'
                  "
                >
                  <el-input
                    v-model="scope.row.settlementDeptName"
                    clearable
                    disabled
                  >
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="是否赠品" prop="isGiveaway" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="isGiveaway"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-checkbox
                    v-model="scope.row.isGiveaway"
                     :disabled="change"
                  ></el-checkbox>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="备注" prop="ramarks" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="ramarks"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.ramarks"
                    :readonly="change ? true : false"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column prop="inventoryUnitName" width="150">
              <template slot="header">
                库存单位<span class="required">*</span>
              </template>
              <template slot-scope="scope">
                <el-form-item
                  label-width="0px"
                  style="margin: 0"
                  :rules="rules.inventoryUnitName"
                  :prop="
                    'materialDetailEntities.' +
                    scope.$index +
                    '.inventoryUnitName'
                  "
                >
                  <el-input
                    v-model="scope.row.inventoryUnitName"
                     :disabled="change"
                    clearable
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                      @click="showDialog('inventoryUnit', scope.$index)"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column label="库存数量" prop="inventoryNum" width="150">
              <template slot-scope="scope">
                <el-form-item
                  prop="inventoryNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.inventoryNum"
                    clearable
                     :disabled="change"
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column
              label="先收票数量(库存基本)"
              prop="receivedFirstTicketsNum"
              width="150"
            >
              <template slot-scope="scope">
                <el-form-item
                  prop="receivedFirstTicketsNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.receivedFirstTicketsNum"
                     disabled
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column
              label="供应商物料编码"
              prop="supplierMaterialCode"
              width="150"
            >
              <template slot-scope="scope">
                <el-form-item
                  prop="supplierMaterialCode"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.supplierMaterialCode"
                    :disabled="change"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column
              label="供应商物料名称"
              prop="supplierMaterialName"
              width="150"
            >
              <template slot-scope="scope">
                <el-form-item
                  prop="supplierMaterialName"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.supplierMaterialName"
                     :disabled="change"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </template>
        </el-collapse-item>
        
 
     
        <!-- 订单列表 -->
        <!-- <div class="desc-title">订单列表</div> -->

        <!-- <el-table
                :data="formObject.orderEntities"
                style="width: 100%"
                highlight-current-row
                border
            >
                <template #empty>
                    <el-button
                        plain
                        type="primary"
                        round
                        @click="addNewRow('order')"
                        >添加新行
                    </el-button>
                </template>
                <el-table-column label="操作" width="120">
                    <template slot-scope="scope">
                        <el-button
                            plain
                            icon="el-icon-plus"
                            size="mini"
                            @click="
                                handleDataAdd_order(scope.$index, scope.row)
                            "
                        ></el-button>
                        <el-button
                            plain
                            icon="el-icon-minus"
                            size="mini"
                            @click="
                                handleDataDelete(
                                    scope.$index,
                                    scope.row,
                                    'order'
                                )
                            "
                        ></el-button>
                    </template>
                </el-table-column>
                <el-table-column label="单据编号">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="orderNumber"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input v-model="scope.row.orderNumber" clearable>
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="getOrderLists(scope.$index)"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="采购日期">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="applyTime"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-date-picker
                                v-model="scope.row.applyTime"
                                type="date"
                                clearable
                                placeholder="选择日期"
                                style="width: 100%"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="供应商">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="supplierName"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input
                                v-model="scope.row.supplierName"
                                clearable
                            ></el-input>
                        </el-form-item>
                        
                    </template>
                </el-table-column>
                <el-table-column label="关闭状态">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="closeState"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input
                                v-model="scope.row.closeState"
                                clearable
                            ></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="订单金额">
                    <template slot-scope="scope">
                        <el-form-item
                            prop="money"
                            label-width="0px"
                            style="margin: 0"
                        >
                            <el-input v-model="scope.row.money"></el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
            </el-table> -->
        <!-- 物料列表 -->
      </el-collapse>
    </el-form>
    <!-- 弹窗 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="open"
      append-to-body
      width="70%"
    >
      <component :is="currentCom" @row-dblclick="getSelectVal"></component>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelSelect">取 消</el-button>
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getCurrencyData, getTaxData, getPayData } from "@/api/base/data";
import {
  getList,
  addProcure,
  editProcureList,
  getDetailProcure,
  saveProcure,
  submitProcure,
} from "@/api/system/contract";

import { convertToRMB } from "@/utils/utils";
import { getOrderDetail } from "@/api/system/purchase";

import { getCompute } from "@/api/finance/info";
import { getMaterial } from "@/api/bim/bim";

import Editor from "./editor/index.vue";
import Project from "@/components/dialog/project";
import Supplier from "@/components/dialog/supplier";
import ProcureOrder from "@/components/dialog/procureOrder";
import queryMaterialList from "@/components/dialog/queryMaterialList";
import payType from "@/components/dialog/payType";
import TaxRate from "@/components/dialog/taxRate";
import Currency from "@/components/dialog/currency";
import PriceUnit from "@/components/dialog/priceUnit";
import SupplierContact from "@/components/dialog/supplierContact";
import RateType from "@/components/dialog/rateType";
import PaymentTerms from "@/components/dialog/paymentTerms";
import deptId from "@/components/dialog/deptId";
export default {
  components: {
    Editor,
    Project,
    Supplier,
    ProcureOrder,
    queryMaterialList,
    payType,
    TaxRate,
    Currency,
    PriceUnit,
    SupplierContact,
    RateType,
    PaymentTerms,
    deptId
  },
  props: { id: String, change: Boolean },
  data() {
    return {
      change:false,
      contractType: "",
      contractTypeOptions: [],
      currentIndex: "", //订单列表 物料列表 当前索引
      currentCom: "",
      activeNames: ['1','2','3','5'],
      formObject: {
        contractProcureEntity: {
          contractContent: "",
          contractName: "",
          contractNumber: "",

          currencyCode: "",
          createBy: "",
          createTime: "",
          deptId: "",
          id: "",

          marginMoney: "",
          marginRate: "",
          money: "",
          moneyUpper: "",
          params: {},
          payType: "",
          payTypeName: "",
          projectId: "",
          projectName: "",
          remark: "",
          remarks: "",
          rate: "",
          searchValue: "",
          signTime: this.parseTime(new Date()),
          supplierId: "",
          supplierName: "",

          taxMoney: "",
          taxRate: "",
          type: 1,
          procureType: "",
          updateBy: "",
          updateTime: "",
          supplierGoodsId: "",
          supplierGoodsName: "",
          supplierContactId: "",
          supplierContactName: "",
          contactPosition: "",
          telPhone: "",
          supplierAddress: "",
          settlementId: "",
          settlementName: "",
          payableId: "",
          payableName: "",
          email: "",
          settlementCurrencyId: "",
          settlementCurrencyName: "",
          priceTimePoint: "",
          standardCurrency: "",
          standardCurrencyName: "",
          standardCurrencyCode: "",
          paymentTerms: "",
          paymentTermsName: "",
          isIncludeTax: 1,
          isExtraPriceTax: 1,
          totalAmountCurrency: "",
          rateType: "",
          rateTypeCode: "",
          rateTypeName: "",
          rate: "",
          startTime: this.parseTime(new Date()),
          endTime: this.parseTime(new Date()),

          businessType: "8",
          modelId: this.$store.state.workflow.businessConfig.id,
        },

        orderEntities: [],
        materialDetailEntities: [],
      },
      rules: {
        materialCode: [
          {
            required: true,
            message: "请输入物料编码",
            trigger: "blur",
          },
        ],
        pricingUnitName: [
          {
            required: true,
            message: "请输入计价单位",
            trigger: "blur",
          },
        ],
        purchaseUnitName: [
          {
            required: true,
            message: "请输入采购单位",
            trigger: "blur",
          },
        ],
        settlementDeptName: [
          {
            required: true,
            message: "请输入结算组织",
            trigger: "blur",
          },
        ],
        inventoryUnitName: [
          {
            required: true,
            message: "请输入库存单位",
            trigger: "blur",
          },
        ],
        contractProcureEntity: {
          contractName: [
            {
              required: true,
              message: "请输入合同名称",
              trigger: "blur",
            },
          ],
          supplierName: [
            {
              required: true,
              message: "请选择供应商",
              trigger: "blur",
            },
          ],
          procureType: [
            {
              required: true,
              message: "请选择合同类型",
              trigger: "blur",
            },
          ],
        },
      },
      typeOptions: [
        {
          label: "普通合同",
          value: 1,
        },
        {
          label: "框架合同",
          value: 2,
        },
        {
          label: "单价合同",
          value: 3,
        },
      ],
      open: false,
      tableData: [],
      total: 0,
      dialogTitle: "",
      loading: true,
      dialogType: "",
      selectItem: [],
    };
  },
  methods: {
    getContractContent(val) {
      this.formObject.contractProcureEntity.contractContent =
        this.contractTypeOptions.find((item) => item.id == val).content;
    },
    // 提交
    submit() {
      const cb = (res) => {
        const obj = {
          id: res.data,
          businessType: "8",
          modelId: this.$store.state.workflow.businessConfig.id,
        };
        submitProcure(obj).then((res) => {
          if (res.code === 200) {
            localStorage.clear('changeid')
            this.$store.commit("workflow/SET_BUSINESSDRAWER", false);
            this.$message({
              message: "提交成功！",
              type: "success",
            });
             
          }
        });
      };
      this.temporaryStorage(cb);
    },

    // 暂存
    temporaryStorage(cb) {
      this.$refs["formRef"].validate((valid) => {
        if (!valid) {
          // cb();
          this.$message.error("请完整填写信息！");
          return;
        }
          if (this.change) {
            // 合同变更
            this.$set(
              this.formObject.contractProcureEntity,
              "parentId",
              this.id
            );
            saveProcure(this.formObject).then((res) => {
              if (res.code === 200) {
                localStorage.clear('changeid')
                this.$store.commit("workflow/SET_BUSINESSDRAWER", false);
                this.$message({
                  message: "合同变更暂存成功！",
                  type: "success",
                });
                
              }
            });
          } else {
           // 新增
          saveProcure(this.formObject).then((res) => {
            if (res.code === 200) {
              localStorage.clear('changeid')
              if (cb) {
                cb(res);
                return;
              }
              this.$store.commit("workflow/SET_BUSINESSDRAWER", false);
              this.$message({
                message: "暂存成功！",
                type: "success",
              });
               
            }
          });
          }
       
          
        
      });
    },
    // 表单重置
    resetForm() {
      this.$refs["formRef"].resetFields();
    },

    // 获取详情回显
    getDetailData(id) {
      getDetailProcure(id).then((res) => {
        this.formObject = res.data;
        // this.getContractTypeOptions(res.data.type);
      });
    },
    // // 新增订单列表
    // handleDataAdd_order() {
    //     if (this.formObject.orderEntities == undefined) {
    //         this.formObject.orderEntities = [];
    //     }
    //     this.formObject.orderEntities.push(this.orderObj);
    // },
    // 新增物料列表
    handleDataAdd_material(index, row) {
      let materialObj = this.getMaterialObj();
      this.formObject.materialDetailEntities.push(materialObj);
      // this.open = false;
    },
    // 删除订单列表
    handleDataDelete(index, row, type) {
      this.$confirm("请确认是否要删除此行?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          if (type === "order") {
            this.formObject.orderEntities.splice(index, 1);
          } else {
            this.formObject.materialDetailEntities.splice(index, 1);
          }
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 新增行
    addNewRow(type) {
      if (type === "order") {
        this.handleDataAdd_order();
      } else {
        this.handleDataAdd_material();
      }
    },
    // 弹出弹窗
    showDialog(type, index) {
      this.open = true;
      this.loading = true;
      this.dialogType = type;
      this.currentIndex = index;
      this.selectItem = [];
      const nameMap = {
        project: () => {
          this.dialogTitle = "选择项目";
          this.currentCom = Project;
        },
        supplier: () => {
          this.dialogTitle = "选择供应商";
          this.currentCom = Supplier;
        },
        supplierGoods: () => {
          this.dialogTitle = "选择供应商";
          this.currentCom = Supplier;
        },
        settlement: () => {
          this.dialogTitle = "选择供应商";
          this.currentCom = Supplier;
        },
        payable: () => {
          this.dialogTitle = "选择供应商";
          this.currentCom = Supplier;
        },
        order: () => {
          this.dialogTitle = "选择订单";
          this.currentCom = ProcureOrder;
        },
        material: () => {
          this.dialogTitle = "选择物料";
          this.currentCom = queryMaterialList;
        },
        pay: () => {
          this.dialogTitle = "选择付款方式";
          this.currentCom = payType;
        },

        taxRate: () => {
          this.dialogTitle = "选择税率";
          this.currentCom = TaxRate;
        },
        currency: () => {
          this.dialogTitle = "选择币别";
          this.currentCom = Currency;
        },
        standardCurrency: () => {
          this.dialogTitle = "选择币别";
          this.currentCom = Currency;
        },
        purchaseUnit: () => {
          this.dialogTitle = "选择单位";
          this.currentCom = PriceUnit;
        },
        pricingUnit: () => {
          this.dialogTitle = "选择单位";
          this.currentCom = PriceUnit;
        },
        inventoryUnit: () => {
          this.dialogTitle = "选择单位";
          this.currentCom = PriceUnit;
        },
        supplierContact: () => {
          this.dialogTitle = "选择供应商联系人";
          this.currentCom = SupplierContact;
        },
        rateType: () => {
          this.dialogTitle = "选择汇率类型";
          this.currentCom = RateType;
        },
        paymentTerms: () => {
          this.dialogTitle = "选择付款条件";
          this.currentCom = PaymentTerms;
        },
        deptId:()=>{
             this.dialogTitle = "选择采购部门";
          this.currentCom = deptId;
        }
        
      };
      nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
    },
    // 弹窗勾选项目
    selectChangeItem(val) {
      this.selectItem = val;
    },

    // 弹窗勾选订单
    selectOrdertem(val) {
      this.selectItem = val;
    },
    // 弹框确认按钮
    confirmSelect(val) {
        this.open = false;
      // const nameMap = {
      //   project: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.projectId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.projectName =
      //       this.selectItem.deptName;
      //     this.open = false;
      //   },
      //   supplier: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.supplierId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.supplierName =
      //       this.selectItem.supplierName;
      //     // 供货方
      //     this.formObject.contractProcureEntity.supplierGoodsId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.supplierGoodsName =
      //       this.selectItem.supplierName;
      //     // 结算方
      //     this.formObject.contractProcureEntity.settlementId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.settlementName =
      //       this.selectItem.supplierName;
      //     // 收款方
      //     this.formObject.contractProcureEntity.payableId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.payableName =
      //       this.selectItem.supplierName;
      //     this.open = false;
      //   },
      //   supplierGoods: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.supplierGoodsId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.supplierGoodsName =
      //       this.selectItem.supplierName;
      //     this.open = false;
      //   },
      //   supplierContact: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.supplierContactId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.supplierContactName =
      //       this.selectItem.name;
      //     this.open = false;
      //   },
      //   order: () => {
      //     this.handleOrder();
      //   },
      //   material: () => {
      //     this.handleMaterial();
      //   },
      //   pay: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.payType = this.selectItem.id;
      //     this.formObject.contractProcureEntity.payTypeName =
      //       this.selectItem.typeName;
      //     this.open = false;
      //   },
      //   rate: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.materialDetailEntities[this.currentIndex].directRate =
      //       this.selectItem.directRate;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].indirectRate = this.selectItem.indirectRate;
      //     this.open = false;
      //     this.caculateNum(
      //       this.formObject.materialDetailEntities[this.currentIndex],
      //       this.currentIndex
      //     );
      //   },
      //   rateType: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.rateType =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.rateTypeCode =
      //       this.selectItem.code;
      //     this.formObject.contractProcureEntity.rateTypeName =
      //       this.selectItem.name;
      //     this.open = false;
      //   },
      //   taxRate: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }

      //     this.formObject.materialDetailEntities[this.currentIndex].taxRate =
      //       this.selectItem.rate;
      //     this.open = false;
      //   },
      //   currency: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.settlementCurrencyName =
      //       this.selectItem.currencyName;
      //     this.formObject.contractProcureEntity.settlementCurrencyId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.rate = this.selectItem.rate;
      //     if (this.formObject.contractProcureEntity.rate) {
      //       this.changeRate(this.formObject.contractProcureEntity.rate);
      //     }
      //     this.open = false;
      //   },
      //   standardCurrency: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.standardCurrencyName =
      //       this.selectItem.currencyName;
      //     this.formObject.contractProcureEntity.standardCurrency =
      //       this.selectItem.id;
      //     this.open = false;
      //   },
      //   pricingUnit: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     // 计价单位
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].pricingUnit = this.selectItem.id;

      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].pricingUnitCode = this.selectItem.meteringUnitCode;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].pricingUnitName = this.selectItem.meteringUnitName;
      //     this.open = false;
      //   },
      //   purchaseUnit: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     // 采购单位 purchaseUnit
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].purchaseUnit = this.selectItem.id;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].purchaseUnitCode = this.selectItem.meteringUnitCode;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].purchaseUnitName = this.selectItem.meteringUnitName;

      //     // 计价单位
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].pricingUnit = this.selectItem.id;

      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].pricingUnitCode = this.selectItem.meteringUnitCode;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].pricingUnitName = this.selectItem.meteringUnitName;

      //     // 库存单位 inventoryUnit
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].inventoryUnit = this.selectItem.id;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].inventoryUnitCode = this.selectItem.meteringUnitCode;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].inventoryUnitName = this.selectItem.meteringUnitName;
      //     this.open = false;
      //   },
      //   inventoryUnit: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     // 库存单位 inventoryUnit
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].inventoryUnit = this.selectItem.id;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].inventoryUnitCode = this.selectItem.meteringUnitCode;
      //     this.formObject.materialDetailEntities[
      //       this.currentIndex
      //     ].inventoryUnitName = this.selectItem.meteringUnitName;
      //     this.open = false;
      //   },
      //   settlement: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.settlementId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.settlementName =
      //       this.selectItem.supplierName;
      //     this.open = false;
      //   },
      //   payable: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.payableId =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.payableName =
      //       this.selectItem.supplierName;
      //     this.open = false;
      //   },
      //   paymentTerms: () => {
      //     if (this.selectItem.length !== 1) {
      //       this.$message.error("请选择一条记录！");
      //       return;
      //     }
      //     this.formObject.contractProcureEntity.paymentTerms =
      //       this.selectItem.id;
      //     this.formObject.contractProcureEntity.paymentTermsName =
      //       this.selectItem.title;
      //     this.open = false;
      //   },
      //   deptId:()=>{
      //   //     if (this.selectItem !='') {
      //   //     this.$message.error("请选择一条记录！");
      //   //     return;
      //   //   }
      //   // console.log(this.selectItem);
        
      //     this.formObject.contractProcureEntity.deptId =
      //       this.selectItem.deptId;
      //     this.formObject.contractProcureEntity.deptName =
      //       this.selectItem.deptName;
      //     this.open = false;
      //   }
      // };
      // nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
    },
    // 物料回显
    handleMaterial() {
        let menulist=[]
        menulist.push(this.selectItem)
      if (this.currentIndex < 0) {
        // 导入物料按钮
        menulist.forEach((item) => {
          let materialObj = this.getMaterialObj();
          Object.keys(item).forEach((itemKey) => {
            Object.keys(materialObj).forEach((materialKey) => {
              if (itemKey === materialKey) {
                materialObj[materialKey] = item[itemKey];
              }
              if (itemKey === "pricingUnitName") {
                materialObj["inventoryUnitName"] = item[itemKey];
              }
              if (itemKey === "pricingUnit") {
                materialObj["inventoryUnit"] = item[itemKey];
              }
            });
          });
          this.formObject.materialDetailEntities.push(materialObj);
        });
      }
      if (this.currentIndex >= 0) {
        // 图标按钮
        // if (this.selectItem.length !== 1) {
        //   this.$message.error("请选择一条记录！");
        //   return;
        // }
        menulist.forEach((item) => {
          let materialObj = this.getMaterialObj();
          Object.keys(item).forEach((itemKey) => {
            Object.keys(materialObj).forEach((materialKey) => {
              if (itemKey === materialKey) {
                materialObj[materialKey] = item[itemKey];
              }
              if (itemKey === "id") {
                materialObj["id"] = "";
              }
              if (itemKey === "pricingUnitName") {
                materialObj["inventoryUnitName"] = item[itemKey];
              }
              if (itemKey === "pricingUnit") {
                materialObj["inventoryUnit"] = item[itemKey];
              }
            });
          });
          this.$set(
            this.formObject.materialDetailEntities,
            this.currentIndex,
            materialObj
          );
        });
      }
      this.open = false;
    },
    // 选单回显
    handleOrder() {
      if (this.selectItem.length === 0) {
        this.$message.error("请选择一条记录！");
        return;
      }
      if (this.selectItem.length >= 1) {
        let flag = this.selectItem.every((item) => {
          return item.supplierId === this.selectItem.supplierId;
        });
        if (!flag) {
          this.$message.error("请选择相同供应商的订单！");
          return;
        }
        this.selectItem.forEach((item) => {
          let materialObj = this.getMaterialObj();
          Object.keys(item).forEach((itemKey) => {
            Object.keys(materialObj).forEach((materialKey) => {
              if (itemKey === materialKey) {
                materialObj[materialKey] = item[itemKey];
              }
              if (itemKey === "materialDetailId") {
                materialObj["sourceMaterialDetailId"] =
                  item["materialDetailId"];
              }
              if (itemKey === "id") {
                materialObj["sourceRelationId"] = item["id"];
              }
              if (materialKey === "id") {
                materialObj["id"] = "";
              }
            });
          });
          this.formObject.materialDetailEntities.push(materialObj);
        });
        getOrderDetail(this.selectItem.id).then((res) => {
          res.data.supplierName
            ? (this.formObject.contractProcureEntity.supplierName =
                res.data.supplierName)
            : "";
          res.data.supplierId
            ? (this.formObject.contractProcureEntity.supplierId =
                res.data.supplierId)
            : "";
        });
        // this.caculateNum(
        //         this.formObject.materialDetailEntities[
        //             this.currentIndex
        //         ],
        //         this.currentIndex
        //     );
        this.open = false;
      }
    },
    // 弹框取消按钮
    cancelSelect() {
      this.open = false;
      this.selectItem = [];
    },
    // 获取物料
    getMaterialLists(index) {
      this.dialogTitle = "物料列表";

      // 不选单
      // getMaterialList().then((res) => {
      //     if (res.code === 200) {
      //         this.loading = false;
      //         this.tableData = res.data.records;
      //         this.total = res.data.total;
      //     }
      // });
      getMaterial().then((res) => {
        if (res.code === 200) {
          this.loading = false;
          this.tableData = res.data.records;
          this.total = res.data.total;
        }
      });
    },
    // 选择物料
    selectMaterialtem(val) {
      this.selectItem = val;
    },
    // 选择弹窗 item
    getSelectVal(val) {
      this.selectItem = val;
      this.open=false
       const nameMap = {
        project: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.projectId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.projectName =
            this.selectItem.deptName;
          this.open = false;
        },
        supplier: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.supplierId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.supplierName =
            this.selectItem.supplierName;
          // 供货方
          this.formObject.contractProcureEntity.supplierGoodsId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.supplierGoodsName =
            this.selectItem.supplierName;
          // 结算方
          this.formObject.contractProcureEntity.settlementId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.settlementName =
            this.selectItem.supplierName;
          // 收款方
          this.formObject.contractProcureEntity.payableId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.payableName =
            this.selectItem.supplierName;
          this.open = false;
        },
        supplierGoods: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.supplierGoodsId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.supplierGoodsName =
            this.selectItem.supplierName;
          this.open = false;
        },
        supplierContact: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.supplierContactId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.supplierContactName =
            this.selectItem.name;
          this.open = false;
        },
        order: () => {
          this.handleOrder();
        },
        material: () => {
          this.handleMaterial();
        },
        pay: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.payType = this.selectItem.id;
          this.formObject.contractProcureEntity.payTypeName =
            this.selectItem.typeName;
          this.open = false;
        },
        rate: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.materialDetailEntities[this.currentIndex].directRate =
            this.selectItem.directRate;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].indirectRate = this.selectItem.indirectRate;
          this.open = false;
          this.caculateNum(
            this.formObject.materialDetailEntities[this.currentIndex],
            this.currentIndex
          );
        },
        rateType: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.rateType =
            this.selectItem.id;
          this.formObject.contractProcureEntity.rateTypeCode =
            this.selectItem.code;
          this.formObject.contractProcureEntity.rateTypeName =
            this.selectItem.name;
          this.open = false;
        },
        taxRate: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }

          this.formObject.materialDetailEntities[this.currentIndex].taxRate =
            this.selectItem.rate;
          this.open = false;
        },
        currency: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.settlementCurrencyName =
            this.selectItem.currencyName;
          this.formObject.contractProcureEntity.settlementCurrencyId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.rate = this.selectItem.rate;
          if (this.formObject.contractProcureEntity.rate) {
            this.changeRate(this.formObject.contractProcureEntity.rate);
          }
          this.open = false;
        },
        standardCurrency: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.standardCurrencyName =
            this.selectItem.currencyName;
          this.formObject.contractProcureEntity.standardCurrency =
            this.selectItem.id;
          this.open = false;
        },
        pricingUnit: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          // 计价单位
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].pricingUnit = this.selectItem.id;

          this.formObject.materialDetailEntities[
            this.currentIndex
          ].pricingUnitCode = this.selectItem.meteringUnitCode;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].pricingUnitName = this.selectItem.meteringUnitName;
          this.open = false;
        },
        purchaseUnit: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          // 采购单位 purchaseUnit
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].purchaseUnit = this.selectItem.id;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].purchaseUnitCode = this.selectItem.meteringUnitCode;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].purchaseUnitName = this.selectItem.meteringUnitName;

          // 计价单位
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].pricingUnit = this.selectItem.id;

          this.formObject.materialDetailEntities[
            this.currentIndex
          ].pricingUnitCode = this.selectItem.meteringUnitCode;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].pricingUnitName = this.selectItem.meteringUnitName;

          // 库存单位 inventoryUnit
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].inventoryUnit = this.selectItem.id;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].inventoryUnitCode = this.selectItem.meteringUnitCode;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].inventoryUnitName = this.selectItem.meteringUnitName;
          this.open = false;
        },
        inventoryUnit: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          // 库存单位 inventoryUnit
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].inventoryUnit = this.selectItem.id;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].inventoryUnitCode = this.selectItem.meteringUnitCode;
          this.formObject.materialDetailEntities[
            this.currentIndex
          ].inventoryUnitName = this.selectItem.meteringUnitName;
          this.open = false;
        },
        settlement: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.settlementId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.settlementName =
            this.selectItem.supplierName;
          this.open = false;
        },
        payable: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.payableId =
            this.selectItem.id;
          this.formObject.contractProcureEntity.payableName =
            this.selectItem.supplierName;
          this.open = false;
        },
        paymentTerms: () => {
        //   if (this.selectItem.length !== 1) {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
          this.formObject.contractProcureEntity.paymentTerms =
            this.selectItem.id;
          this.formObject.contractProcureEntity.paymentTermsName =
            this.selectItem.title;
          this.open = false;
        },
        deptId:()=>{
        //     if (this.selectItem !='') {
        //     this.$message.error("请选择一条记录！");
        //     return;
        //   }
        console.log(this.selectItem);
        
          this.formObject.contractProcureEntity.deptId =
            this.selectItem.deptId;
          this.formObject.contractProcureEntity.deptName =
            this.selectItem.deptName;
          this.open = false;
        }
      };
      nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
    },
    // 计算值
    caculateNum(row, index) {
      // 数量，税率，价税合计，汇率
      if (row == undefined) {
        return;
      }
      if (row.number >= 0) {
        // 计价数量
        this.$set(
          this.formObject.materialDetailEntities[index],
          "pricingNum",
          row.number
        );
        //   库存数量
        this.$set(
          this.formObject.materialDetailEntities[index],
          "inventoryNum",
          row.number
        );
      }
      if (row.totalTaxPrice) {
        // 合同总金额本位币=主表上总价税合计*汇率
        const total = this.formObject.materialDetailEntities.reduce(
          (sum, item) => sum + Number(item.totalTaxPrice),
          0
        );
        this.formObject.contractProcureEntity.totalAmountCurrency =
          total * this.formObject.contractProcureEntity.rate;
        // 合同金额 = 价税合计之和
        this.formObject.contractProcureEntity.money = total;
        this.formObject.contractProcureEntity.moneyUpper = convertToRMB(total);
      }

      if (
        row.number &&
        row.taxRate &&
        row.totalTaxPrice &&
        this.formObject.contractProcureEntity.rate
      ) {
        let totalTaxAmount = row.totalTaxPrice;
        let number = row.number;
        let taxRate = row.taxRate;
        let rate = this.formObject.contractProcureEntity.rate;
        getCompute({ number, taxRate, totalTaxAmount, rate }).then((res) => {
          this.$set(
            this.formObject.materialDetailEntities[index],
            "price",
            res.data.price
          );
          this.$set(
            this.formObject.materialDetailEntities[index],
            "amountMoney",
            res.data.amount
          );

          this.$set(
            this.formObject.materialDetailEntities[index],
            "taxAmount",
            res.data.taxAmount
          );

          this.$set(
            this.formObject.materialDetailEntities[index],
            "taxPrice",
            res.data.taxUnitPrice
          );
        });
      }
    },
    // 汇率
    changeRate(value) {
      this.formObject.materialDetailEntities.forEach((item, index) => {
        if (
          item.number &&
          item.taxRate &&
          item.totalTaxPrice &&
          this.formObject.contractProcureEntity.rate
        ) {
          let totalTaxAmount = item.totalTaxPrice;
          let number = item.number;
          let taxRate = item.taxRate;
          let rate = this.formObject.contractProcureEntity.rate;
          getCompute({
            number,
            taxRate,
            totalTaxAmount,
            rate,
          }).then((res) => {
            this.$set(
              this.formObject.materialDetailEntities[index],
              "price",
              res.data.price
            );
            this.$set(
              this.formObject.materialDetailEntities[index],
              "amountMoney",
              res.data.amount
            );

            this.$set(
              this.formObject.materialDetailEntities[index],
              "taxAmount",
              res.data.taxAmount
            );

            this.$set(
              this.formObject.materialDetailEntities[index],
              "taxPrice",
              res.data.taxUnitPrice
            );
          });
        }
      });
    },
    getMaterialObj() {
      let obj = {
        amountMoney: "",
        batchNum: "",
        businessTaxCostPrice: "",
        changeTime: "",
        changeType: "",
        containsTaxPrice: "",
        createTime: "",
        deliveryAddress: "",
        deliveryDate: this.parseTime(new Date()),
        deliveryLocation: "",
        discountAmount: "",
        discountRate: "",
        executeStatus: "",
        id: "",
        sourceMaterialDetailId: "",
        inventoryId: "",
        inventoryNum: 0,
        inventoryUnit: "",
        inventoryUnitCode: "",
        inventoryUnitName: "",
        isGiveaway: false,

        limit: 0,
        material: {
          allowAsset: "",
          allowInventory: "",
          allowOutsource: "",
          allowProduce: "",
          allowPurchase: "",
          allowSale: "",
          barCode: "",
          brand: "",
          businessType: "",
          configurationProduction: "",
          costPriceRatio: "",
          createBy: "",
          createTime: "",
          dataState: "",
          defaultTaxRate: "",
          deptId: "",
          disableBy: "",
          examineBy: "",
          examineTime: "",
          grossWeight: "",
          heightStr: "",
          id: "",
          imgUrl: "",
          instanceId: "",
          inventoryType: "",
          isChange: "",

          kit: "",
          lengthStr: "",
          materialCode: "",
          materialDesc: "",
          materialGroup: "",
          materialInventoryEntity: {
            batchInfo: "",
            batchRule: "",
            checkCycle: "",
            convertDirection: "",
            costUnit: "",
            createBy: "",
            createTime: "",
            currency: "",
            day: "",
            economicOrderingBatch: "",
            id: "",
            inventoryUnit: "",
            isBatch: "",
            isCheck: "",
            isLock: "",
            isMaxInventory: "",
            isMinInventory: "",
            isOrderGoods: "",
            isSafeInventory: "",
            isTrueCheck: "",
            materialId: "",
            maxInventoyNum: "",
            minInventoryNum: "",
            orderGoodsNum: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            qualityManage: "",
            qualityNum: "",
            qualityUnit: "",
            referenceCost: "",
            remark: "",
            safeInventoryNum: "",
            searchValue: "",
            serviceLife: "",
            standardNumber: "",
            supportUnit: "",
            updateBy: "",
            updateTime: "",
            warePosition: "",
            warehouseCode: "",
          },
          materialName: "",
          materialPlanAttributeEntity: {
            createBy: "",
            createTime: "",
            fAllowPartDelay: "",
            fBaseVarLeadTimeLotSize: "",
            fBaseVarLeadTimeLotSizeUnit: "",
            fCanDelayDays: 0,
            fCanLeadDays: 0,
            fCheckLeadTime: 0,
            fCheckLeadTimeType: "",
            fDelayExtendDay: 0,
            fFixLeadTime: 0,
            fFixLeadTimeType: "",
            fIncreaseQty: 0,
            fIncreaseQtyUnit: "",
            fIsMrpComBill: "",
            fIsMrpComReq: "",
            fLeadExtendDay: 0,
            fMaxPoqty: 0,
            fMfgPolicyId: "",
            fMinPoqty: 0,
            fMinPoqtyUnit: "",
            fOrderIntervalTime: 0,
            fOrderIntervalTimeType: "",
            fOrderPolicy: "",
            fPlanBatchSplitQty: "",
            fPlanBatchSplitQtyUnit: "",
            fPlanGroupId: "",
            fPlanIdent: "",
            fPlanIntervalsDays: 0,
            fPlanOffsetTime: 0,
            fPlanOffsetTimeType: "",
            fPlanSafeStockQty: 0,
            fPlanSafeStockQtyUnit: "",
            fPlanTimeZone: 0,
            fPlanWorkshop: "",
            fPlanerId: "",
            fPlanningStrategy: "",
            fProScheTrackId: "",
            fProductLine: "",
            fRequestTimeZone: 0,
            fSupplySourceId: "",
            fVarLeadTime: 0,
            fVarLeadTimeLotSize: "",
            fVarLeadTimeLotSizeUnit: "",
            fVarLeadTimeType: "",
            fWriteOffQty: "",
            fWriteOffQtyUnit: "",
            id: "",
            materialId: "",
            maxPoqtyUnit: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialProcureEntity: {
            agentProcure: "",
            barCodeRule: "",
            createBy: "",
            createTime: "",
            dayProduction: 0,
            dayProductionUnit: "",
            defaultSupplier: "",
            defunctProductionLine: "",
            expenseItem: "",
            id: "",
            isControl: "",
            isDayProduction: "",
            isMaterialReturn: "",
            isQuota: "",
            isReq: "",
            materialId: "",
            minPackNum: "",
            minSpiltNum: 0,
            outsourcePricingUnit: "",
            outsourceType: "",
            outsourceUnit: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            procureGroup: "",
            procureId: "",
            procurePricingUnit: "",
            procureType: "",
            procureUnit: "",
            quotaMode: "",
            remark: "",
            repeatPutNum: "",
            searchValue: "",
            takeOverDelay: 0,
            takeOverDown: "",
            takeOverLead: 0,
            takeOverUp: "",
            updateBy: "",
            updateTime: "",
          },
          materialProductEntity: {
            createBy: "",
            createTime: "",
            deptId: "",
            fBackFlushType: "",
            fConsumVolatility: "",
            fDefaultLineId: "",
            fDefaultRouting: "",
            fFinishReceiptOverRate: "",
            fFinishReceiptShortRate: "",
            fIsCompleteSet: "",
            fIsEnableSchedule: "",
            fIsKitting: "",
            fIsMainPrd: "",
            fIsMinissueQty: "",
            fIsProductLine: "",
            fIsSNCarryToParent: "",
            fIssueType: "",
            fMdlId: "",
            fMdlMaterialId: "",
            fMinissueQty: 0,
            fMinissueUnitId: "",
            fOrgTrustBillType: "",
            fOverControlMode: "",
            fPerUnitStandHour: "",
            fPickBinId: "",
            fPickStockId: "",
            fProduceBillType: "",
            fProduceUnitId: "",
            fStandHourUnitId: "",
            fStdLaborPrePareTime: "",
            fStdLaborProcessTime: "",
            fStdMachinePrepareTime: "",
            fStdMachineProcessTime: "",
            fWorkShopId: "",
            fbkfltime: "",
            fbomunitid: "",
            ffixloss: "",
            fisecn: "",
            flosspercent: "",
            id: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialProperty: "",
          materialQualityEntity: {
            createBy: "",
            createTime: "",
            fCheckDelivery: "",
            fCheckEntrusted: "",
            fCheckIncoming: "",
            fCheckOther: "",
            fCheckProduct: "",
            fCheckReturn: "",
            fCheckStock: "",
            fCheckSubFtnMtrl: "",
            fEWLeadDay: "",
            fEnableCyclistQCSTK: "",
            fEnableCyclistQcstkew: "",
            fFirstQCControlType: "",
            fIncQcSchemeId: "",
            fIncSampSchemeId: "",
            fInspectGroupId: "",
            fInspectorId: "",
            fIsFirstInspect: "",
            fStockCycle: "",
            id: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            searchValue: "",
            updateBy: "",
            updateTime: "",
          },
          materialSaleEntity: {
            allowReleaseOrder: "",
            allowReturns: "",
            atpCheck: "",
            controlSurpassUnit: "",
            createBy: "",
            createTime: "",
            dropOutCount: "",
            fisReturnPart: "",
            fisaftersale: "",
            fisproductfiles: "",
            fiswarranted: "",
            fwarranty: "",
            fwarrantyunitid: "",
            id: "",
            isFavourableTax: "",
            materialId: "",
            pageNo: 0,
            pageSize: 0,
            params: {},
            remark: "",
            saleDownPrice: "",
            saleGroup: "",
            saleOutbound: "",
            salePricingUnit: "",
            saleUnit: "",
            searchValue: "",
            startOrderNum: 0,
            surpassDown: "",
            surpassUp: "",
            taxType: "",
            taxTypeCode: "",
            updateBy: "",
            updateTime: "",
          },
          mnemonicCode: "",
          model: "",
          modelId: "",
          netWeight: "",
          oldMaterialCode: "",
          pageNo: 0,
          pageSize: 0,
          params: {},
          reasonForDisable: "",
          remark: "",
          searchValue: "",
          sizeUnit: "",
          state: "",
          subItems: "",
          taxType: "",
          typeName: "",
          unit: "",
          updateBy: "",
          updateTime: "",
          volume: "",
          weightUnit: "",
          wideStr: "",
        },
        materialCode: "",
        materialName: "",
        materialId: "",
        model: "",
        netAmount: "",
        noTaxMoney: "",
        number: 0,
        orderDelivery: {
          batchNum: "",
          bomVer: "",
          changeTime: "",
          controlDeliveryNum: true,
          controlDeliveryTime: true,
          createTime: "",
          deliveryDelayDay: "",
          deliveryDown: "",
          deliveryEarlyTime: "",
          deliveryLatestTime: "",
          deliveryLeadDay: "",
          deliveryUp: "",
          id: "",

          materialId: "",
          materialName: "",
          orderDeliveryDetails: [
            {
              address: "",
              changeTime: "",
              confirmComment: "",
              confirmNum: "",
              confirmTime: "",
              createTime: "",
              deliveredNum: "",
              deliveryTime: "",
              id: "",

              location: "",
              num: "",
              orderDeliveryId: "",
              orderId: "",
              planUnit: "",
              surplusNum: "",
              userId: "",
            },
          ],
          orderId: "",
          receiveDept: "",
          receiveOrg: "",
          requireDept: "",
          requireOrg: "",
          supplierBatch: "",
          supportAttr: "",
          userId: "",
        },
        orderFinanceDetail: {
          changeTime: "",
          createTime: "",
          discountAmount: "",
          discountRate: "",
          entryPriceInfo: "",
          id: "",

          materialCode: "",
          materialId: "",
          materialName: "",
          netPrice: "",
          orderId: "",
          priceCeiling: "",
          priceCoefficient: "",
          priceFloor: "",
          pricingNum: "",
          pricingUnit: "",
          settlementDept: "",
          systemPricing: "",
          taxRate: "",
          unitPriceDiscount: "",
          userId: "",
        },
        orderOther: {
          businessClose: "",
          businessFreeze: "",
          businessProcess: "",
          businessStop: "",
          changeTime: "",
          contractsCode: "",
          createTime: "",
          freezeName: "",
          freezeTime: "",
          id: "",
          inventoryReturnNum: "",
          isPlanConfirm: "",
          isQuotaGeneration: "",

          materialCode: "",
          materialId: "",
          materialName: "",
          materialReceivedReturnNum: "",
          orderId: "",
          planTrackingCode: "",
          requireDocCode: "",
          requireDocLineCode: "",
          requireFrom: "",
          requireTrackingCode: "",
          sourceDocCode: "",
          sourceDocType: "",
          stopName: "",
          stopTime: "",
          surplusInboundNum: "",
          surplusMaterialReceivedNum: "",
          totalInboundNum: "",
          totalMaterialReceivedNum: "",
          totalMaterialReturnNum: "",
          updateFlag: "",
          userId: "",
        },
        originalContainsTaxPrice: "",
        originalNumber: "",
        page: 0,
        parentMaterial: "",
        price: "",
        pricingNum: "",
        pricingUnit: "",
        pricingUnitCode: "",
        pricingUnitName: "",
        purchaseUnit: "",
        purchaseUnitCode: "",
        purchaseUnitName: "",
        ramarks: "",
        receivedFirstTicketsNum: "",
        receivingDept: "",
        receivingDeptName: "",
        relationId: "",
        requireDept: "",
        requireDeptName: "",
        settlementDept: "",
        settlementDeptName: "",
        sourceDocCode: "",
        sourceDocType: "",
        sourceRelationId: "",
        supplierMaterialCode: "",
        supplierMaterialName: "",
        taxAmount: "",
        taxMoney: "",
        taxPrice: "",
        taxRate: "",
        token: "",
        totalAcceptanceAmount: "",
        totalAcceptanceRate: "",
        totalTaxPrice: "",
        type: 0,
        warehouseId: "",
        warehouseRegionId: "",
        directRate: "",
        indirectRate: "",
      };
      //默认税率13%
      getTaxData().then((res) => {
        obj.taxRate = res.rows[0].rate;
      });
      return obj;
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }
        if (
          column.property === "number" ||
          column.property === "pricingNum" ||
          column.property === "amountMoney" ||
          column.property === "taxAmount" ||
          column.property === "totalTaxPrice"
        ) {
          const values = data.map((item) => Number(item[column.property]));
          if (!values.every((value) => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += "";
          } else {
            sums[index] = "N/A";
          }
        } else {
          return;
        }
      });

      return sums;
    },
    // 初始化默认数据
    initDefaultData() {
      // 结算币别
      getCurrencyData().then((res) => {
        this.formObject.contractProcureEntity.settlementCurrencyId =
          res.rows[0].id;
        this.formObject.contractProcureEntity.settlementCurrencyName =
          res.rows[0].currencyName;
        this.formObject.contractProcureEntity.currencyCode = res.rows[0].code;
        // 本位币
        this.formObject.contractProcureEntity.standardCurrency = res.rows[0].id;
        this.formObject.contractProcureEntity.standardCurrencyName =
          res.rows[0].currencyName;
        this.formObject.contractProcureEntity.standardCurrencyCode =
          res.rows[0].code;
        this.formObject.contractProcureEntity.rate = res.rows[0].rate;
      });
      // 付款条件
      getPayData({ type: 2 }).then((res) => {
        this.formObject.contractProcureEntity.paymentTerms = res.rows[0].id;
        this.formObject.contractProcureEntity.paymentTermsName =
          res.rows[0].title;
      });
    },
  },
  created() {
    // 初始化默认数据
    this.initDefaultData();
    // 获取合同类型
    getList({
      typeId: 183,
    }).then((res) => {
      if (res.code === 200) {
        this.contractTypeOptions = res.rows.map((item) => {
          return {
            id: item.id,
            value: item.id,
            label: item.tempName,
            content: item.contractTempContent,
          };
        });
      }
    });
         
    // 获取详情回显
    if (localStorage.getItem('changeid')) {      
      this.getDetailData(localStorage.getItem('changeid'));
      this.change=true
    }
  },
  destroyed() {
     localStorage.clear('changeid')
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-table td.el-table__cell div {
  overflow: visible;
}

::v-deep .el-table td.el-table__cell {
  padding-bottom: 20px;
}
</style>
